<template>
  <div class="bg-light">
    <!-- 头部 -->
    <div class="header d-flex align-items-center">
      <router-link to="/politics" class="text-dark">
        <i class="bi bi-chevron-left fs-4"></i>
      </router-link>
      <h5 class="mb-0 mx-auto">专项练习</h5>
    </div>

    <!-- 科目卡片列表 -->
    <router-link 
      v-for="subject in subjects" 
      :key="subject.examPaperId"
      :to="`/politics/special/practice?examPaperId=${subject.examPaperId}`"
      class="text-decoration-none"
    >
      <div class="subject-card">
        <h6 class="subject-title">
          <i class="bi bi-book-fill"></i>
          {{ subject.name }}
        </h6>
        <div class="progress">
          <div 
            class="progress-bar" 
            :style="`width: ${subject.progress}%`"
          ></div>
        </div>
        <div class="stats-info">
          <span>已完成{{ subject.progress }}%</span>
          <span>{{ subject.completedCount }}/{{ subject.totalCount }}题</span>
        </div>
      </div>
    </router-link>
  </div>
</template>

<script>
import {paperTypeDict} from "@/router/dict";
import http from "@/router/http";
import router from "@/router";

export default {
  name: 'PoliticsSpecialView',
  data() {
    return {
      subjects: [
        // {
        //   id: 1,
        //   name: '马克思主义基本原理',
        //   code: 'marx',
        //   progress: 75,
        //   completedCount: 150,
        //   totalCount: 200
        // },
        // {
        //   id: 2,
        //   name: '毛泽东思想和中国特色社会主义理论',
        //   code: 'mzd',
        //   progress: 60,
        //   completedCount: 120,
        //   totalCount: 200
        // },
        // {
        //   id: 3,
        //   name: '中国近现代史纲要',
        //   code: 'history',
        //   progress: 45,
        //   completedCount: 90,
        //   totalCount: 200
        // },
        // {
        //   id: 4,
        //   name: '思想道德与法治',
        //   code: 'law',
        //   progress: 30,
        //   completedCount: 60,
        //   totalCount: 200
        // }
      ]
    }
  },
  mounted() {
    const paperType = paperTypeDict.find(item => item.label === '专项练习').value;
    http.get('/student/question/getQuestionSpecialPoliticsList?paperType='+paperType)
        .then(response => {
          const data = response.data.response;
          data.forEach(item => {
            this.subjects.push({
              examPaperId: item.examPaperId,
              name: item.questionTitile,
              progress: item.completeRate,
              completedCount: item.numberQuestionsCompleted,
              totalCount: item.questionTotalNum,
            });
          });

          // this.yearCards = response.data;
        })
        .catch(error => {
          console.error('获取政治专项练习题数据失败：', error);
          alert('获取政治专项练习题数据失败，请稍后再试');
          router.push('/politics');
        });
  },
}
</script>

<style scoped>
body {
  background-color: #f0f9f9;
  padding-bottom: 70px;
}

.header {
  padding: 15px;
  background: white;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.subject-card {
  background: white;
  margin: 15px;
  padding: 20px;
  border-radius: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.subject-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.subject-title {
  color: #B19CD9;
  margin-bottom: 10px;
}

.progress {
  height: 6px;
  margin: 15px 0;
}

.progress-bar {
  background-color: #B19CD9;
}

.stats-info {
  display: flex;
  justify-content: space-between;
  color: #666;
  font-size: 0.9rem;
}
</style> 